//
//  RMMAdressTableViewCell.m
//  Romomo
//
//  Created by puman on 16/10/12.
//  Copyright © 2016年 mazegong. All rights reserved.
//

#import "RMMAdressTableViewCell.h"

@implementation RMMAdressTableViewCell
{
    UILabel *_nameLabel;
    UIButton *_moRenBut;
    UILabel *_adressLabel;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        _button = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _button.frame = CGRectMake(0, 0, 50, 75);
        _button.userInteractionEnabled = NO;
        [self.contentView addSubview:_button];
        
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_button.right, 14, 3 * kHalf + kMaric, kMaric)];
        _nameLabel.textColor = COLORFROMCODE(0x393939, 1);
        _nameLabel.font = kFont(16);
        [self.contentView addSubview:_nameLabel];
        
        _adressLabel = [[UILabel alloc] initWithFrame:CGRectMake(_button.right, _nameLabel.bottom, kScreenWideth - 39 - _button.right, 41)];
        _adressLabel.numberOfLines = 0;
        _adressLabel.textColor = COLORFROMCODE(0x4A4A4A, 1);
        _adressLabel.font = kFont(14);
        [self.contentView addSubview:_adressLabel];

        _moRenBut = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _moRenBut.frame = CGRectMake(_nameLabel.right + 5, _nameLabel.top + 1, 36, 18);
        [_moRenBut setTitleColor:kWhiteColor forState:(UIControlStateNormal)];
        [_moRenBut setTitle:@"默认" forState:(UIControlStateNormal)];
        _moRenBut.titleLabel.font = kFont(12);
        _moRenBut.backgroundColor = kBasicColor;
        _moRenBut.layer.masksToBounds = YES;
        _moRenBut.layer.cornerRadius = 3;
        _moRenBut.userInteractionEnabled = NO;
        [self.contentView addSubview:_moRenBut];
        
        _editorBut = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _editorBut.frame = CGRectMake(kScreenWideth - 39, 0, 29, 75);
        [self.contentView addSubview:_editorBut];

        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(_button.right, 0, kScreenWideth - _button.right - 36, 75)];
        [self.contentView addSubview:_titleLabel];
        _titleLabel.hidden = YES;
        _titleLabel.font = kFont(14);

    }
    return self;
}
- (void)setDic:(NSDictionary *)dic{
    _nameLabel.text = [NSString stringWithFormat:@"%@ %@",dic[@"ADD_NAME"],dic[@"MOBILE"]];
    if ([dic[@"REGION_NAME"] isKindOfClass:[NSNull class]]) {
        
    }
    _adressLabel.text = [NSString stringWithFormat:@"%@ %@ %@ %@",dic[@"PROVINCE_NAME"],dic[@"CITY_NAME"],dic[@"REGION_NAME"],dic[@"DE_ADDRESS"]];
    NSLog(@"%@",dic[@"REGION_NAME"]);
    if ([dic[@"TYPE"] isEqualToNumber:@0]) {
        _moRenBut.hidden = YES;
    } else {
        _moRenBut.hidden = NO;
    }

}
- (void)setNumber:(NSNumber *)number{
    if ([number isEqualToNumber:@0]) {
        _titleLabel.text = @"请选择服务地址";
        _titleLabel.hidden = NO;
        _moRenBut.hidden = YES;
        _adressLabel.hidden = YES;
        _nameLabel.hidden = YES;
        _editorBut.hidden = YES;
        _titleLabel.textColor = kBasicColor;
        [_button setImage:[UIImage imageNamed:@"定位@2x"] forState:(UIControlStateNormal)];
        _editorBut.frame = CGRectMake(kScreenWideth - 59, 0, 29, 75);

    }
    if ([number isEqualToNumber:@1]) {
        _titleLabel.hidden = YES;
        _adressLabel.hidden = NO;
        _nameLabel.hidden = NO;
        _editorBut.hidden = NO;
        [_button setImage:[UIImage imageNamed:@"可选@2x"] forState:(UIControlStateNormal)];
        [_editorBut setImage:[UIImage imageNamed:@"编辑地址@2x"] forState:(UIControlStateNormal)];
        _editorBut.frame = CGRectMake(kScreenWideth - 39, 0, 29,75);
    }
    if ([number isEqualToNumber:@2]) {
        _titleLabel.hidden = YES;
        _moRenBut.hidden = YES;
        _adressLabel.hidden = NO;
        _nameLabel.hidden = NO;
        _editorBut.hidden = NO;
        [_button setImage:[UIImage imageNamed:@"定位@2x"] forState:(UIControlStateNormal)];
        _editorBut.hidden = YES;

    }
}
- (void)setMineSet:(NSString *)mineSet{
    _button.hidden = YES;
}
- (void)setWarning:(NSString *)warning{
    _titleLabel.textColor = [UIColor redColor];
    _editorBut.hidden = NO;
    [_button setImage:[UIImage imageNamed:@"dingweijg"] forState:(UIControlStateNormal)];
    [_editorBut setImage:[UIImage imageNamed:@"3@2x"] forState:(UIControlStateNormal)];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
